﻿@using TamoCRM.Domain.Channels
@model TamoCRM.Web.Mvc.Areas.Admin.Models.Contacts.ContactSearchModel
@{
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@{
    List<TamoCRM.Domain.Collectors.CollectorInfo> collectors = ViewBag.Collectors1;
    List<TamoCRM.Domain.Channels.ChannelInfo> channels = ViewBag.Channels1;
    List<TamoCRM.Domain.ImportExcels.ImportExcelInfo> imports = ViewBag.ImportExcels1;

    var lstCollectors = new SelectList(collectors, "CollectorId", "Name");
    var lstChannels = new SelectList(channels, "ChannelId", "Name");
    var lstImportExcels = new SelectList(imports, "ImportId", "FilePath");
}


<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try { ace.settings.check('breadcrumbs', 'fixed') } catch (e) { }
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="/Home">Trang chủ</a>
        </li>

        <li>
            <a href="javascript:void(0);">Danh mục</a>
        </li>
        <li class="active">Contact</li>
    </ul>
</div>

<div class="page-content">
    <div class="page-header">
        <h1>Contact bị lỗi 						
        </h1>
    </div>
    <!-- /.page-header -->

    <div class="row">
        <div class="col-xs-12">
            <div id="alert"></div>
        </div>
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->
            <div class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-1 control-label no-padding-right" for="form-field-1" style="text-align: left !important;">Người lấy </label>
                    <div class="col-sm-2">

                        @Html.DropDownListFor(x => x.CollectorId, lstCollectors, new { @class = "form-control" })

                    </div>
                    <label class="col-sm-0 control-label no-padding-right" for="form-field-2">Kênh </label>
                    <div class="col-sm-2">
                        @Html.TextBoxFor(x => x.ChannelName)
                        <input type="hidden" id="ChannelId" name="ChannelId" value="0" />
                    </div>
                    <label class="col-sm-0 control-label no-padding-right" for="form-field-3">File </label>
                    <div class="col-sm-2">
                        @Html.DropDownListFor(x => x.ImportId, lstImportExcels, new { @class = "form-control" })

                    </div>
                </div>

                <div class="space-4"></div>
                <div class="form-group">
                    <div class="col-sm-12">
                        <button id="btnSearch" type="button" class="btn-import btn-primary" value="Import">Tìm</button>
                    </div>
                </div>
            </div>

            <table id="grid-table"></table>

            <div id="grid-pager"></div>


            <!-- PAGE CONTENT ENDS -->
        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
</div>
<!-- /.page-content -->

<!-- inline scripts related to this page -->

<script type="text/javascript">
    var grid_selector = "#grid-table";
    var heades = ['Thao tác', 'Id', 'Họ tên', 'Ngày sinh', 'Di động 1', 'Di động 2', 'Điện thoại nhà', 'Email'];
    var model = [
        {
            name: 'act', index: '', width: 80, fixed: true, sortable: false, resize: false,
            formatter: 'actions',
            formatoptions: {
                keys: true,

                delOptions: {
                    recreateForm: true, beforeShowForm: beforeDeleteCallback, delData: {
                        ContactId: function () {
                            var sel_id = $(grid_selector).jqGrid('getGridParam', 'selrow');
                            var value = $(grid_selector).jqGrid('getCell', sel_id, 'ContactId');
                            return value;

                        }
                    }
                },
                onSuccess: function (response) {
                    //alert(response.responseText);
                    $("#spiner").addClass("alert alert-block alert-success");
                    $("#spiner").html(response.responseText);
                    $("#btnSearch").click();
                    return [true];
                }
            }
        },
        { name: 'ContactId', index: 'ContactId', width: 60, editable: true, sorttype: 'int', editoptions: { disabled: 'true' }, width: 50 },
        { name: 'Fullname', index: 'Fullname', editable: true, sorttype: 'string' },
        { name: 'Birth', index: 'Birth', editable: true, sorttype: 'string' },
        { name: 'Mobil1', index: 'Mobil1', editable: true, sorttype: 'string' },
        { name: 'Mobil2', index: 'Mobil2', editable: true, sorttype: 'string' },
        { name: 'Tel', index: 'Tel', editable: true, sorttype: 'string' },
        { name: 'Email', index: 'Email', editable: true, sorttype: 'string' }

    ];
    var someRetValue;
    $(document).ready(function () {
        $("#ChannelName").change(function(e) {
            e.preventDefault();
            $("#btnSearch").attr("disabled", "disabled");
            if ($("#ChannelName").val().trim() == '') {
                $("#ChannelId").val('0');
                return;
            }
            $.ajax({
                type: "POST",
                url: "/admin/api/channel/getbycode/",
                data: {code : $("#ChannelName").val() }
            }).done(function(res) {
                if (res != null) {
                    $("#ChannelId").val(res.ChannelId);
                } else {
                    $("#ChannelId").val("-1");
                }
                $("#btnSearch").removeAttr("disabled");
            });
        });
        setupGridTable(grid_selector, "#grid-pager", "admin/api/contacttmp/get?collectorId=" + $("#CollectorId").val() + "&channelId=" + $("#ChannelId").val() + "&importId=" + $("#ImportId").val() + "&levelId=0&sourceTypeId=0&branchId=" + @TamoCRM.Web.Framework.Users.UserContext.GetDefaultBranch(), "admin/api/contacttmp/edit", "ContactId", "Contact bị lỗi", heades, model, "", 10, '350px');
        setupGridPagerWithoutEdit(grid_selector, "#grid-pager", "admin/api/contacttmp/get?collectorId=" + $("#CollectorId").val() + "&channelId=" + $("#ChannelId").val() + "&importId=" + $("#ImportId").val() + "&levelId=0&sourceTypeId=0&branchId=" + @TamoCRM.Web.Framework.Users.UserContext.GetDefaultBranch(), "admin/api/contacttmp/edit", "ContactId", "Contact bị lỗi", heades, model);
        
        $("#btnSearch").click(function (e) {
            e.preventDefault();
            var newUrl = "/admin/api/contacttmp/get?collectorId=" + $("#CollectorId").val() + "&channelId=" + $("#ChannelId").val() + "&importId=" + $("#ImportId").val() + "&levelId=0&sourceTypeId=0&branchId=" + "@TamoCRM.Web.Framework.Users.UserContext.GetDefaultBranch()";
            jQuery(grid_selector).jqGrid().setGridParam({ url: newUrl }).trigger("reloadGrid");
        });
    });
</script>

